<template>
  <div>
    <div class="work-experience primary-text" v-if="form.sta != 4 || form.editSta != data.id">
      <el-row>
        <el-col :span="20" class="work-experience-head">
          <!--一级建造师-->
          {{data.parentLicenseType}}-{{data.sonLicenseType}}
          <span
            class="work-license"
          >{{data.licenseNum}}</span>
        </el-col>
        <el-col :span="2" class="orange-text">
          <div @click="editContent(data.id)">
            <img src="../../../assets/img/resume/bianji.png" width="14px" height="14px" />
            编辑
          </div>
        </el-col>
        <el-col :span="2" class="orange-text">
          <div @click="doDelete(data.id)">
            <img src="../../../assets/img/resume/detele.png" width="14px" height="14px" />
            删除
          </div>
        </el-col>
      </el-row>
    </div>

    <div class="edit-content" v-if="form.sta == 4 && form.editSta == data.id">
      <div class="all-job-resume" style="padding:24px 0 0 0; background:#f7fdff;">
        <el-form label-width="100px" label-position="right">
          <el-row>
            <el-col :span="12">
              <el-form-item label="执业类型">
                <!-- <el-select class="all-input" v-model="data.licenseTypeId">
                  <el-option
                    v-for="(item,index) in practiceType"
                    :key="index"
                    :value="item.id"
                    :label="item.content"
                  ></el-option>
                </el-select>-->
                <el-cascader :options="practiceType||[]" :props="props" v-model="licenseIds"></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="11" :offset="1">
              <el-form-item label="证书编号">
                <el-input class="theme-input all-input" v-model="data.licenseNum"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item class="form-button-right">
            <el-button class="ghost-button" @click="cancel">取消</el-button>
            <el-button class="submit-button" @click="doSubmit">确认</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['form', 'data', 'practiceType', 'lengths'],
  data() {
    return {
      sta: 4,
      licenseIds: [],
      props: {
        value: 'licenseTypeId',
        children: 'licenseSonList',
        label: 'licenseType'
      }
    }
  },
  methods: {
    check() {
      if (this.data.licenseNum == '' || this.data.licenseTypeId == '') {
        _g.message('数据不能为空', 'warning')
        return false
      }
      return true
    },
    editContent(id) {
      //工作经历编辑方法
      this.form.sta = 4
      this.form.editSta = id
    },
    doDelete(id) {
      console.log(this.lengths, '长度')
      if (this.lengths > 1) {
        _g.apiPost('/talent/deleteLicense.do', { licenseId: id }).then(res => {
          _g.toMessage(res)
          this.$emit('on-pitch', true)
        })
      } else {
        _g.message('执业证书至少保留一项', 'warning')
      }
    },
    cancel() {
      this.$emit('on-pitch', true)
      this.form.sta = -1
      this.form.editSta = -1
    },
    doSubmit() {
      if (!this.check()) return false
      let params = {
        licenseId: this.data.id,
        licenseNum: this.data.licenseNum,
        licenseType: this.licenseIds[1]
      }
      _g.apiPost('/talent/updateLicense.do', params).then(res => {
        _g.toMessage(res.data)
        this.cancel()
      })
    },
    setData() {
      this.licenseIds = JSON.parse(this.data.licenseIds)
    }
  },
  mounted() {
    this.setData()
  },
  components: {}
}
</script>

<style lang="scss" scoped>
</style>
